package com.iqiju.guagua.photo.wx.mini.handler;

import com.alibaba.fastjson.JSON;
import com.iqiju.guagua.photo.wx.mini.common.Results;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 登录过期/未登录  handler
 */
@Slf4j
public class LoginExpireHandler implements AuthenticationEntryPoint {

    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response,
                         AuthenticationException authException) throws IOException, ServletException {
        response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
        Results results = new Results(401,"登录过期或未登录",null);
        log.warn("form login 登录过期或者未登录=============");
        response.getWriter().write(JSON.toJSONString(results));
    }
}

